package com.user.infrastructure.repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.user.domain.repository.UserSignInRepository;
import com.user.infrastructure.entity.SignDao;
import com.user.infrastructure.repository.mapper.SignMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author 大忽悠
 * @create 2022/9/16 8:48
 */
@Repository
@RequiredArgsConstructor
public class UserSignInRepositoryImpl implements UserSignInRepository {
    private final SignMapper signMapper;

    @Override
    public void signInNumAdd(Integer userId) {
        SignDao record = signMapper.selectOne(new QueryWrapper<SignDao>().eq("user_id", userId));
        if(record==null){
            signMapper.insert(SignDao.builder().userId(userId).signNum(1).build());
        }else {
            record.setSignNum(record.getSignNum()+1);
            signMapper.updateById(record);
        }
    }
}
